package repository.impl;

import entity.Patient;
import entity.PatientsInfo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import repository.PatientsInfoRepository;

import java.util.List;

@Transactional
@Repository
public class PatientsInfoRepositoryImpl implements PatientsInfoRepository {
    @Autowired
    private SessionFactory sessionFactory;

    public Session getCurrentSession() {
        return this.sessionFactory.getCurrentSession();
    }

    public PatientsInfo load(Integer id) {
        return (PatientsInfo) getCurrentSession().load(PatientsInfo.class, id);
    }

    public PatientsInfo get(Integer id) {
        return (PatientsInfo) getCurrentSession().get(PatientsInfo.class, id);
    }

    public List findAll() {
        return getCurrentSession().createQuery("from " + PatientsInfo.class.getName()).list();
    }

    public void persist(PatientsInfo entity) {
        getCurrentSession().persist(entity);
    }

    public Integer save(PatientsInfo entity) {
        return (Integer) getCurrentSession().save(entity);
    }

    public void saveOrUpdate(PatientsInfo entity) {
        getCurrentSession().saveOrUpdate(entity);
    }

    public void delete(Integer id) {
        PatientsInfo patientsInfo = load(id);
        getCurrentSession().delete(patientsInfo);
    }

    public void flush() {
        getCurrentSession().flush();
    }
}
